/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package LDVH.tests;

import LDVH.itf.IGestObjetsFactory;
import LDVH.itf.ILivre;
import LDVH.itf.ISection;
import LDVH.livre.GestLivre;
import LDVH.factories.GestObjetsBouchonFactory;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;

/**
 *
 * @author daniele
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TesterCLivre {
    private ILivre sut;
    private ISection section1, section2;
    private int toto, soleil;
    
    @Before
    public void setUp() {
        IGestObjetsFactory bouchonFactory = new GestObjetsBouchonFactory();
        sut = new GestLivre(bouchonFactory);
        sut.creerSection("section1");
        sut.creerSection("section2");
        section1 = sut.getSection("section1");
        section2 = sut.getSection("section2");
        toto = sut.getGestObjet().ajouterObjet("toto");
        soleil = sut.getGestObjet().ajouterObjet("soleil");
        section1.ajouterObjet(toto);
        section1.ajouterObjet(soleil);
    }
      
    @Test
    public void testGetGestObjets() {
        assertNotNull(sut.getGestObjet());
    }
    
    @Test
    public void testAjouterObjet() {
        assertFalse(section1.ajouterObjet(toto));
        int objId = sut.getGestObjet().ajouterObjet("new");
        assertTrue(section1.ajouterObjet(objId));
    }
    
    @Test
    public void testSupprimerObjet() {
        assertTrue(section1.supprimerObjet(toto));
        assertFalse(section1.supprimerObjet(toto));
        sut.getGestObjet().supprimerObjet(toto);
        assertEquals("", sut.getGestObjet().getDescription(toto));
    }
        
    @Test
    public void testListerObjets() {
        List<String> noms = new ArrayList<>();
        List<String> toTest = new ArrayList<>();
        noms.add("toto");
        noms.add("soleil");        
        
        for (int id : section1.listerObjets())
            toTest.add(sut.getGestObjet().getDescription(id));
        
        assertTrue(toTest.containsAll(noms));
        assertTrue(noms.containsAll(toTest));
    }
    
    @Test
    public void testAjouterCondition() {
        List<String> noms = new ArrayList<>();
        List<String> toTest = new ArrayList<>();
        noms.add("toto");
        noms.add("soleil");   
        
        section1.creerEnchainement(section2);
        section1.ajouterCondition(section2, toto);
        section1.ajouterCondition(section2, soleil);
        
        for (int id : section1.getConditions(section2))
            toTest.add(sut.getGestObjet().getDescription(id));
    
        assertTrue(toTest.containsAll(noms));
        assertTrue(noms.containsAll(toTest));
    }
}
